package cn.buk.tms.entity.misc;

import java.util.Date;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

/**
 * 乘机人的证件细信息
 * @author yfdai
 */
@Entity
@Table(name="t602")
public class PassengerIdInfo {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;

    @Column(name="enterprise_id", updatable = false, nullable = false)
    private int enterpriseId;

    @ManyToOne
    @JoinColumn(name = "passenger_id", foreignKey = @ForeignKey(name = "fk_passenger_id"))
    private Passenger passenger;

    /**
     * 证件类型
     */
    @Column(name = "id_type")
    private int idType;

    /**
     * 证件号
     */
    @Column(name = "id_no", length = 20)
    private String idNo;

    /**
     * 证件签发国家/地区
     */
    @Column(name = "id_issue_nation", length = 3)
    private String idIssueNation;

    /**
     * 证件有效期
     */
    @Column(name = "id_valid_date")
    @Temporal(TemporalType.DATE)
    private Date idValidDate;


    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time", insertable = false, updatable = false)
    private Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update", insertable = false)
    private Date lastUpdate;

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + getIdNo().hashCode();
        result = 31 * result + getIdType();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;//地址相等
        }

        if(obj == null){
            return false;//非空性：对于任意非空引用x，x.equals(null)应该返回false。
        }

        if(obj instanceof PassengerIdInfo){
            PassengerIdInfo other = (PassengerIdInfo) obj;
            //需要比较的字段相等，则这两个对象相等
            return this.getIdNo().equalsIgnoreCase(other.getIdNo())
                    && this.getIdType() == other.getIdType();
        }

        return false;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public Passenger getPassenger() {
        return passenger;
    }

    public void setPassenger(Passenger passenger) {
        this.passenger = passenger;
    }

    public int getIdType() {
        return idType;
    }

    public void setIdType(int idType) {
        this.idType = idType;
    }

    public String getIdNo() {
        return idNo == null ? "": idNo.trim();
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getIdIssueNation() {
        return idIssueNation;
    }

    public void setIdIssueNation(String idIssueNation) {
        this.idIssueNation = idIssueNation;
    }

    public Date getIdValidDate() {
        return idValidDate;
    }

    public void setIdValidDate(Date idValidDate) {
        this.idValidDate = idValidDate;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }
}
